﻿using Microsoft.AspNetCore.Mvc;
using Qy.Common;
using Qy.Web.Authorize;
using System.Collections.Generic;

namespace Qy.Web.Api
{
    [Route("Api/[controller]/[action]")]
    [Verify]
    public class CacheController : Base
    {
        private readonly ICacheManager _cacheManager;
        public CacheController(ICacheManager cacheManager)
        {
            _cacheManager = cacheManager;
        }

        [HttpGet]
        [ActionPermissionFilter(Permission = PermissionKeys.Cache_Index)]
        public IActionResult Index()
        {
            string name = AppSettings.App(new string[] { "CacheService", "CacheEngine" });
            List<ViewCacheModel> cacheList;
            if (name == "Redis")
            {
                cacheList = new()
                    {
                        new ViewCacheModel() { Name = "Redis(启用)", Val = _cacheManager.TotalNumber(), Size = 0 },
                        new ViewCacheModel() { Name = "Memory", Val = 0, Size = 0 },
                    };
            }
            else
            {
                cacheList = new()
                    {
                        new ViewCacheModel() { Name = "Redis", Val = 0, Size = 0 },
                        new ViewCacheModel() { Name = "Memory(启用)", Val = _cacheManager.TotalNumber(), Size = 0 },
                    };
            }
            return Json(new { status = 1, data = cacheList });
        }
    }
}
